def is_prime(s):
    if s <= 1:
        return False
    
    for i in range(2, int(s ** 0.5) + 1):
        if s % i == 0:
            return False
    return True

def largest_prime_from_digits(s):
    s = str(s)
    if len(s)!= 4 or not s.isdigit():
        return 0
    max_prime = 0
    for i in range(len(s)):
        for j in range(i + 1, len(s) + 1):
            num = int(s[i:j])
            if is_prime(num) and num > max_prime:
                max_prime = num
    return max_prime
s = int(input('Напиши число:'))
result = largest_prime_from_digits(s)
print(result)